package cn.xmy.demo01.servlet;
import cn.xmy.demo01.pojo.Icon;
import cn.xmy.demo01.service.IconService;
import cn.xmy.demo01.service.impl.IconServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/findActionIconServlet")
public class FindActionIconServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        IconService iconService=new IconServiceImpl();
        try {
            List<Icon> icons=iconService.findAction();
            String a= JSON.toJSONString(icons);
            PrintWriter out=response.getWriter();
            out.println(a);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
